{/* 我要送礼(DisShopBuyGifts/confirmOrder) */ }

{__NOLAYOUT__}
<layout name="no_nav" />

<!-- TOPBAR -->
<header class="top-bar flex-row">
  <a class="row-item row-item-auto top-bar-back" href="javascript:window.history.back()">返回</a>
  <h3 class="row-item top-bar-name">提交订单</h3>
  <a class="row-item row-item-auto top-bar-menu" href="{$config.url}">主页</a>
</header>

<form action="__CONTROLLER__/confirmOrderPost" method="post">
  
  <!-- 配送以及支付 -->
  <section class="pr-order-item">
    <p>
      <span>支付方式：</span>
      <select id="pay-apitype" name="apitype">{$order.productPayApiOptions}</select>  
    </p>
  </section>
  

  <!-- 商品清单 -->
  <section class="pr-order-item pr-good-list">

    <h5 class="pr-good-list-title">商品清单：共&nbsp;{:count($order['orderItems'])}&nbsp;件商品</h5>
    
    <section class="pr-good-list-container">
      <volist name="order.orderItems" id="vo">
      <volist name="vo.items" id="vo_attr">
      <div class="pr-good-item flex-row">
        <a class="pr-good-pic row-item row-item-3" href="javascript:;">
          <img src="{$vo_attr.pic}">
        </a>
        <div class="pr-good-info row-item row-item-7">
          <p>{$vo.name}</p>
          <notempty name="vo_attr['attrs']">
          <p>规格：<foreach name="vo_attr.attrs" item="vo1" key="k">{$k}:{$vo1}&nbsp;&nbsp;</foreach></p>
          </notempty>
          <p>
            <span data-subprice="{$vo_attr.productPrice}">单价：{$vo_attr.productPrice}元</span>
            <span>数量：{$vo_attr.quantity}</span>
          </p>
        </div>
      </div>
      </volist>
      </volist>
    </section>

  </section>
  
  <section class="pr-order-item">
  
    <p class="pr-order-money">
      <span>商品总金额</span>
      <span class="fr">{$order.goodsTotalPrice}元</span>
    </p>
    <p class="pr-order-money">
      <span>运费</span>
      <span class="fr" id="freight">{$order['shippingTotalPrice']}元</span>
    </p>
    <p class="pr-order-money total">
      <span>订单总计</span>
      <span class="fr" id="total-price">{$order.totalPrice}元</span>
    </p>
    
	<if condition="$order['id'] eq '' || in_array('pay', $order['operates'])">
    <button type="submit" class="btn btn-orange w100 pr-btn">去结算</button>
    </if>
    
	<if condition="in_array('cancel', $order['operates'])">
	<button id="order-cancel-btn" type="button" class="btn btn-white w100 pr-btn" data-id="{$order.id}">取消订单</button>
	</if>
	
  </section>
  
  <input type="hidden" name="orderId" value="{$order.id}">{/* 订单id（已保存待支付订单有此值） */}
  <input type="hidden" name="addressId" value="{$order.address.id}">
  <input type="hidden" name="orderNo" value="{$order.orderNo}">
  <input type="hidden" name="sid" value="{$sid}">
  
</form>

<script src="__COMMON__/js/modal.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
  (function() {
	var sid = "{$sid}";
	$("#order-cancel-btn").click(function() {
			$this = $(this);
			modal.confirm({
				'title': '取消订单提示',
				'text': '确定要取消此订单吗？',
				'callback': function() {
					$.ajax({
						type: "POST",
						url: "{:U('DisShopOrder/cancelOrder')}",
						async: true,
						data: {
							id: $this.attr("data-id"),
							sid: sid,
						},
						success: function(response) {
							APP.alert(response.msg);
							if (response.error == 0) {
								window.location.href="{:U('DisShopGiftsOrder/showOrder', 'id='.$order['id'].'&sid='.$sid)}";
							}
						},
						error: function() {
							APP.alert("网络错误，请重试！");
						}
					});
				}
			});
			return false;
		});
  })();

  $(function(){

    $(".pr-good-list-title").on("tap", function(){
      $(this).parent().toggleClass("open");
    });

  });
</script>